package com.jz.work.util;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import java.util.Properties;


public class JDBCEncrypt extends PropertyPlaceholderConfigurer {
	private static final String key = "0001020110022002";

	@SuppressWarnings("static-access")
	protected void processProperties(
            ConfigurableListableBeanFactory beanFactory, Properties props)
			throws BeansException {
		try {
			Des des = new Des();
			String username = props.getProperty("username");
			if (username != null) {
				props.setProperty("username", des.Decrypt(username, des.hex2byte(key)));
			}

			String password = props.getProperty("password");
			if (password != null) {
				props.setProperty("password", des.Decrypt(password, des.hex2byte(key)));
			}

			String url = props.getProperty("url");
			if (url != null) {
				props.setProperty("url", des.Decrypt(url, des.hex2byte(key)));
			}

			String url1 = props.getProperty("url1");
			if (url != null) {
				props.setProperty("url1", des.Decrypt(url1, des.hex2byte(key)));
			}

			String driverClassName = props.getProperty("driver");
			if (driverClassName != null) {
				props.setProperty("driver", des.Decrypt(driverClassName, des.hex2byte(key)));
			}

			super.processProperties(beanFactory, props);
		} catch (Exception e) {
			e.printStackTrace();
			throw new BeanInitializationException(e.getMessage());
		}
	}
}
